// 继承基础模块，自身可见时会加载数据
define(function( require, exports ){
	var pubjs = require('pubjs');
	var view = require('@base/view');

	var Base = view.widget.extend({
		init: function(config){
			config = pubjs.conf(config, {
				// 只加载一次数据（reset可重置）
				'load_once': true,
				'layout': {
					'module': view.container,
					'auto_load': false
				}
			});
			this.Super('init', arguments);
			this.$isDataLoaded = false;
		},
		setParam: function() {
			var mod = this.getLayout();
			if(mod.setParam)
			{
				return mod.setParam.apply(mod, arguments);
			}

			return this;
		},
		reset: function() {
			var mod = this.getLayout();
			this.$isDataLoaded = false;
			return mod.reset.apply(mod, arguments);
		},
		setData: function() {
			var mod = this.getLayout();
			return mod.setData.apply(mod, arguments);
		},
		getData: function() {
			var mod = this.getLayout();
			return mod.getData.apply(mod, arguments);
		},
		setValue: function() {
			var mod = this.getLayout();
			return mod.setValue.apply(mod, arguments);
		},
		getValue: function() {
			var mod = this.getLayout();
			return mod.getValue.apply(mod, arguments);
		},
		load: function(reload, args) {
			var self = this;
			var mod = this.getLayout();
			var c = self.getConfig();
			pubjs.checkDisplay(self, 'load', function(){
				if (!self.$isDataLoaded || reload || !c.load_once) {
					self.$isDataLoaded = true;
					mod.load(args);
				}
			});
		},
		onStartLoadData: function(ev) {
			this.load();
		}
	});
	exports.base = Base;
});